import urllib.request
import urllib.parse


import string


def get_parmas():
    url = 'http://www.baidu.com/s?'

    params = {
        "wd":"中文",
        "key":"张",
        "value":"三"
    }

    str_params = urllib.parse.urlencode(params)
    print(str_params)

    final_url = url + str_params
    print(final_url)
    # 将带有中文的 url 转译成 计算机 http识别的url
    encode_url = urllib.parse.quote(final_url, safe=string.printable)
    print(encode_url)

    response = urllib.request.urlopen(encode_url)

    data = response.read().decode('utf-8')

    with open('03-get.html', 'w', encoding='utf-8') as f:
        f.write(data)

    # print(data)


get_parmas()
